<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pages_Entity extends CI_Model
{
    private $tablename = 'pages';
    private $id = null;
    private $title = null;
    private $alias = null;
    private $contents = null;
    private $changed = null;
    private $created = null;
    private $status = null;
    private $order = null;
    private $keyword = null;
    private $description = null;
    private $hit = null;
    
    public function setId($Id)
    {
        $this->id = $Id;
    }

    public function setTitle($Title)
    {
        $this->title = $Title;
    }

    public function setAlias($Alias)
    {
        $this->alias = $Alias;
    }

    public function setContents($Contents)
    {
        $this->contents = $Contents;
    }

    public function setChanged($Changed)
    {
        $this->changed = $Changed;
    }

    public function setCreated($Created)
    {
        $this->created = $Created;
    }

    public function setStatus($Status)
    {
        $this->status = $Status;
    }

    public function setOrder($Order)
    {
        $this->order = $Order;
    }

    public function setKeyword($Keyword)
    {
        $this->keyword = $Keyword;
    }

    public function setDescription($Description)
    {
        $this->description = $Description;
    }

    public function setHit($Hit)
    {
        $this->hit = $Hit;
    }

    public function save()
    {
        $params = array();
        foreach ($this as $key => $val) {
            if ($key == 'tablename') continue;
            if ($val === null || $val === '') continue;
            $params[$key] = $val;
        }
                
        if (!isset($params['id'])) {
            if ($this->db->insert($this->tablename, $params)) {
                return $this->db->insert_id();
            } else {
                return 0;
            }
        } else {
            return $this->db->update($this->tablename, $params, array('id' => $params['id']));
        }
        
    }
    
    public function del($id)
    {
        
        return $this->db->delete($this->tablename, array('id' => $id));    
    }
    
    public function getPagesById($id)
    {
        $query = $this->db->get_where($this->tablename, array('id' => $id));
        if ($query->num_rows() > 0) {
            return $query->row();
        }
        return false;
    }
    
    public function getAllList()
    {
        $query = $this->db->get($this->tablename);
        return $query->result();
    }
    
    public function TotalPages()
    {
        $query = $this->db->count_all_results('Pages'); 
        return $query->result();
    } 
}       
        